import axios from "axios";

const server = axios.create({
    baseURL:'http://localhost:8080',
    timeout:60000
})

server.interceptors.request.use(config=>{
    console.log("请求拦截器")
    // 拦截所有请求 在请求头中添加信息
    let token = sessionStorage.getItem('token')
    config.headers['token'] = token
    return config
},error=>{
    return Promise.reject(error);
})

server.interceptors.response.use(resp=>{
    console.log('响应拦截器')
    if(resp.data.status == false){
        // jwt认证失败
        alert('长时间未操作,请重新登录')
        sessionStorage.removeItem("token")
        window.location.href = '/login'
    }
    return resp;
},error=>{
    return Promise.reject(error)
})

export default server